package com.runing.controller;


import com.runing.config.ResponseWrapper;
import com.runing.entity.RStudent;
import com.runing.service.impl.RStudentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/rStudent")
@Api(tags = "学生信息管理")
public class RStudentController {
    @Autowired
    RStudentServiceImpl studentService;

    @ApiOperation("按照id查询一个学生信息")
    @ApiImplicitParam(name = "sid",value = "学生id")
    @GetMapping("/selectStudent")
    public ResponseWrapper selectStudent(@RequestParam(name = "sid")Integer sid){
        ResponseWrapper wrapper = studentService.findStudentById(sid);
        return wrapper;
    }

    @ApiOperation("修改学生")
    @PutMapping("/updataStudent")
    public ResponseWrapper updataStudent(@RequestBody RStudent rStudent){
        ResponseWrapper wrapper = studentService.updataStudent(rStudent);
        return wrapper;
    }
    @ApiOperation("修改某个学生的成绩")
    @PutMapping("/updateResult")
    public ResponseWrapper updateResult(@RequestParam(name = "sid")Integer sid,
                                        @RequestParam(name = "inclasses")String inclasses,
                                        @RequestParam(name = "spe")String spe){
        ResponseWrapper wrapper = studentService.updateResult(sid,inclasses,spe);
        return wrapper;
    }

    @ApiOperation("移动端登录")
    @PostMapping("/mobileLogin")
    public ResponseWrapper mobileLogin(@RequestBody RStudent rStudent){
        ResponseWrapper wrapper = studentService.mobileLogin(rStudent);
        return wrapper;
    }

    @ApiOperation("按照clid查询某个班的所有学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "sname",value = "学生姓名"),
            @ApiImplicitParam(name = "clid",value = "班级id")
    })
    @GetMapping("/getStuByclid")
    public ResponseWrapper getStuByclid(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                        @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                        @RequestParam(name = "clid")Integer clid,
                                        @RequestParam(name = "sname",required = false)String sname){
        ResponseWrapper wrapper = studentService.findstudentByClid(clid,pageSize,pageNum,sname);
        return wrapper;
    }

    @ApiOperation("模糊查询某个班的学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "clid",value = "班级id"),
            @ApiImplicitParam(name = "sname",value = "学生姓名"),
    })
    @GetMapping("/searchSname")
    public ResponseWrapper searchSname(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                       @RequestParam(name = "clid")Integer clid,
                                       @RequestParam(name = "sname",required = false)String sname){
        ResponseWrapper wrapper = studentService.findStudentBySerach(clid,pageSize,pageNum,sname);
        return wrapper;
    }

    @ApiOperation("图片上传")
    @PostMapping("/picUpload")
    public ResponseWrapper picUpload(@RequestParam("file") MultipartFile file) throws IOException {
        ResponseWrapper wrapper =studentService.picUpload(file);
        return  wrapper;
    }

    @ApiOperation("导入execl")
    @PostMapping("/UploadExcel")
    public ResponseWrapper ajaxUploadExcel(@RequestParam(value="excelFile",required = false) MultipartFile excelFile) throws ParseException {
        ResponseWrapper wrapper = studentService.UploadExcel(excelFile);
        return wrapper;
    }

    @ApiOperation("导出excel")
    @GetMapping("/excel")
    public void excel( HttpServletResponse response,@RequestParam(name = "clid")Integer clid)throws IOException {
        studentService.excel(response,clid);
        return;
    }

    @ApiOperation("查询所有开挂的学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findBadStudent")
    public ResponseWrapper findBadStudent(@RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                          @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = studentService.findBadStudent(pageSize,pageNum);
        return wrapper;
    }
}

